from load_data import *

import numpy as np
import os
from collections import defaultdict

interval = 100


def count_ts(ts):
    count_dict1 = defaultdict(lambda: 0)
    count_dict2 = defaultdict(lambda: 0)
    fr_count = 0
    c_count = 0
    for t in ts:
        count_dict1[t] += 1
    for frames, c in count_dict1.items():
        fr_count += frames
        c_count += c
        k = int(frames/interval)
        count_dict2[int(k * interval / 100)] += c
    print(sorted(count_dict2.items(), key=lambda x: x[0]))
    print('avg :', fr_count/c_count)


def count_test_ts():
    loaded_data = load_data()
    test_ts = loaded_data.test_ts
    count_ts(test_ts)


def count_err_ts(err_file):
    ts = []
    with open(err_file, 'r') as f:
        for line in f:
            eles = line.split()
            if len(eles) == 2:
                t = int(eles[1])
                ts.append(t)
    count_ts(ts)


if __name__ == '__main__':
    # count_test_ts()
    count_err_ts('./err_file.txt')

